package com.suoluo.zenadmin.controllers.admin.friend;

import javax.annotation.Resource;

import net.paoding.rose.web.Invocation;
import net.paoding.rose.web.annotation.Param;
import net.paoding.rose.web.annotation.Path;
import net.paoding.rose.web.annotation.rest.Get;
import net.paoding.rose.web.annotation.rest.Post;

import com.suoluo.zenadmin.common.CommonResp;
import com.suoluo.zenadmin.controllers.JSONInterceptor.JSON;
import com.suoluo.zenadmin.service.friend.FriendService;
import com.suoluo.zenadmin.vo.friend.FriendItemVO;
import com.suoluo.zenadmin.vo.friend.FriendTypeVO;

@Path("/")
public class FriendController {

	@Resource(name="friendService")
	private FriendService friendService;
	
	@Get("type/vlist")
	public String toListFriendType()
	{
		return "listFriendType";
	}
	@JSON
	@Post("type/list")
	public Object listFriendType()
	{
		return friendService.findListFriendType();
	}
	@Get("type/vsave")
	public String toAddFriendType()
	{
		return "addFriendType";
	}
	@JSON
	@Post("type/save")
	public Object saveFriendType(FriendTypeVO typePOJO)
	{
		friendService.saveFriendType(typePOJO);
		return CommonResp.SUCCESS;
	}
	
	@Get("type/vupdate")
	public String toUpdateFriendType(Invocation invo,@Param("friendTypeId")int typeId)
	{
		FriendTypeVO typePOJO = friendService.findFriendTypeById(typeId);
		invo.addModel("friendType",typePOJO);
		return "updateFriendType";
	}
	@JSON
	@Post("type/update")
	public Object updateFriendType(FriendTypeVO typePOJO)
	{
		friendService.updateFriendType(typePOJO);
		return CommonResp.SUCCESS;
	}
	@JSON
	@Post("type/delete")
	public Object deleteFriendType(@Param("friendTypeId")int typeId)
	{
		friendService.deleteFriendType(typeId);
		return CommonResp.SUCCESS;
	}
	
	
	@Get("item/vlist")
	public String toListFriendItem(Invocation invo,@Param("friendTypeId")int typeId)
	{
		FriendTypeVO friendType = friendService.findFriendTypeById(typeId);
		invo.addModel("friendType",friendType);
		return "listFriendItem";
	}
	@JSON
	@Post("item/list")
	public Object listFriendItem(@Param("friendTypeId")int typeId)
	{
		return friendService.findListFriendItem(typeId);
	}
	@Get("item/vsave")
	public String toAddFriendItem(Invocation invo,@Param("friendTypeId")int friendTypeId)
	{
		int maxOrder = friendService.findFriendItemMaxOrder();
		maxOrder = maxOrder +1;
		invo.addModel("maxOrder",maxOrder);
		invo.addModel("friendTypeId",friendTypeId);
		return "addFriendItem";
	}
	@JSON
	@Post("item/save")
	public Object saveFriendItem(FriendItemVO itemVO)
	{
		friendService.saveFriendItem(itemVO);
		return CommonResp.SUCCESS;
	}
	
	@Get("item/vupdate")
	public String toUpdateFriendItem(Invocation invo,@Param("friendItemId")int itemId)
	{
		FriendItemVO itemPOJO = friendService.findFriendItemById(itemId);
		invo.addModel("friendItem",itemPOJO);
		return "updateFriendItem";
	}
	@JSON
	@Post("item/update")
	public Object updateFriendItem(FriendItemVO itemVO)
	{
		friendService.updateFriendItem(itemVO);
		return CommonResp.SUCCESS;
	}
	@JSON
	@Post("item/delete")
	public Object deleteFriendItem(FriendItemVO itemVO)
	{
		friendService.deleteFriendItem(itemVO);
		return CommonResp.SUCCESS;
	}
	
}
